package com.dy.placeOrder.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dy.placeOrder.service.CollectionService;
import com.dy.placeOrder.Collection;
import com.dy.placeOrder.util.SensitiveFilter;
import com.dy.placeOrder2.service.OrdersService;
import com.dy.pojo.Orders;
import com.kaoshi.common.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("placeOrder/collection")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private SensitiveFilter sensitiveFilter;

    @GetMapping("getCollectionOrders")
    public Result getCollectionOrders(Integer uid) {
        return collectionService.getCollectionOrders(uid);
    }
    @GetMapping("getNumber")
    public int getCollectionNumber(Integer uid) {
        // 使用 lambda 查询构建器
        LambdaQueryWrapper<Collection> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Collection::getUid, uid);

        // 调用 count 方法
        int count = collectionService.count(queryWrapper);
        return count;
    }
    @GetMapping("getShoppingCartNumber")
    public int getShoppingCartNumber(Integer uid) {
        // 使用 lambda 查询构建器
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Orders::getUid, uid);
        queryWrapper.eq(Orders::getGstatus, 1);
        // 调用 count 方法
        int count = ordersService.count(queryWrapper);
        return count;
    }

    @RequestMapping("findCollection")
    public Boolean findCollection(@RequestParam Integer uid,@RequestParam Integer gid) {
        Boolean flag = collectionService.findCollection(uid,gid);
        return flag;
    }

    @RequestMapping("cancel")
    public Result cancel(@RequestParam Integer uid,@RequestParam Integer gid) {
        collectionService.cancel(uid,gid);
        return Result.ok();
    }
    @RequestMapping("collection")
    public Result collection(@RequestParam Integer uid,@RequestParam Integer gid) {
        System.out.println("uid="+uid+" gid="+gid);

        if (uid == null || gid == null) {
            System.out.println("参数不能为空");
        }

        collectionService.collection(uid,gid);
        return Result.ok();
    }


}
